import jsonpAdapter from 'axios-jsonp';

import { baseUrlApi, requestClient, type Result } from '#/api/request';

export const refreshAccessToken = (params: object) => {
  return requestClient.get<Result>(
    'https://www.thinkcmf.com/api/appstore/login/refreshAccessToken',
    { params },
  );
};

export const doLogin = (params: object) => {
  return requestClient.get<Result>(
    'https://www.thinkcmf.com/appstore/login/doLogin',
    { adapter: jsonpAdapter, params },
  );
};

export const postDoLogin = (data: object) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/app_store/doLogin`),
    data,
  );
};

/** 应用市场配置 */
export const getAppstoreSettings = () => {
  return requestClient.get<Result>(
    baseUrlApi(`/admin/app_store/appstoreSettings`),
  );
};

/** 应用列表 */
export const getApps = (params: object) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/app_store/apps`), {
    params,
  });
};

/** 插件列表 */
export const getPlugins = (params: object) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/app_store/plugins`), {
    params,
  });
};

/** 主题列表 */
export const getThemes = (params: object) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/app_store/themes`), {
    params,
  });
};

/** 安装应用 */
export const postApps = (data: { id: number; version?: string }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/app_store/installApp`),
    data,
  );
};

/** 安装插件 */
export const postPlugins = (data: { id: number; version?: string }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/app_store/installPlugin`),
    data,
  );
};

/** 安装插件 */
export const postThemes = (data: { id: number; version?: string }) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/app_store/installTheme`),
    data,
  );
};
